package com.gzz.orchid.context.application.rbac.impl;

import com.gzz.orchid.context.application.rbac.IUserHandler;
import com.gzz.orchid.context.application.rbac.convert.UserConverter;
import com.gzz.orchid.context.application.rbac.pojo.UserDto;
import com.gzz.orchid.context.application.rbac.pojo.UserVo;
import com.gzz.orchid.context.application.rbac.queries.UserQuery;
import com.gzz.orchid.context.infrastructure.persistence.entity.sys.SysUserPo;
import com.gzz.orchid.context.infrastructure.persistence.mapper.sys.SysUserMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author higmd
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class UserHandler implements IUserHandler {
    private final SysUserMapper mapper;

    @Override
    public List<UserDto> listByPager(UserQuery query) {
        List<SysUserPo> poList = mapper.selectListByPage(query.toQueryWrap(), query.getPager());
        return UserConverter.INSTANCE.mapDtoList(poList);
    }

    @Override
    public List<UserDto> list(UserQuery query) {
        return List.of();
    }

    @Override
    public UserVo detail(Long id) {
        SysUserPo po = mapper.getById(id);
        return Optional.ofNullable(po)
                .map(UserConverter.INSTANCE::mapVo)
                .orElse(null);
    }
}
